<template>
  <van-list
    v-model:loading="loading"
    :finished="finished"
    finished-text="没有更多了"
    @load="onLoad"
  >
    <div v-for="item in list" :key="item" class="py-2 px-4">
      <div class="flex justify-between">
        <span>
          {{ item.seller.name }}
        </span>
        <span>
          {{ $ymdhm(item.created_at) }}
        </span>
      </div>
      <div
        v-for="order_item in item.items"
        :key="order_item.id"
        class="flex justify-between"
      >
        <span>{{ order_item.goods_name }}</span>
        <span>{{ $ymdhm(item.updated_at) }}</span>
      </div>
      <div class="flex justify-between">
        <span>
          {{ item.customer.nickname }}
        </span>
        <span> ￥ {{ $formatMoney(item.real_total) }} </span>
      </div>
    </div>
  </van-list>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1,
      search: 'this-week=1',
    }
  },
  methods: {
    onLoad() {
      //   const token = window.sessionStorage.getItem('token')
      const token = this.$route.query.token
      const headers = { Authorization: `Bearer ${token}` }
      this.axios
        .get(`/income?page=${this.page}&${this.search}`, { headers })
        .then((res) => {
          let { result, sum, count } = res.data
          this.list = [...this.list, ...result]
          this.$emit('refresh-sum', { sum, count })
          this.page++
          this.loading = false
          if (res.data.result.length < 20) {
            this.finished = true
          }
        })
    },
    reload(search) {
      this.search = search
      this.list = []
      this.page = 1
      this.finished = false
      this.onLoad()
    },
  },
}
</script>

<style></style>
